<% if flash[:notice]  -%>
  <div class="sysmsg"><%= flash[:notice] -%></div>
  <% flash[:notice] = nil -%>
<% end -%>
<% if session[:user_name] == nil -%>
<table id="columns">
  <tr>
    <td id="main">
      <p id="headline">Microblog anything, anytime, anywhere!</p>
      <ul id="slogan">
        <li id="what"><p>Microblog<br/>Note everything in your life.</p></li>
        <li id="who"><p>Meet and Share<br/>Make you and your friends closer.</p></li>
        <li id="how"><p>Everywhere<br/>Not yet supported. :P</p></li>
      </ul>
      <p id="get-started"><a href="/signup">Sign Up!</a></p>
    </td>
    <!-- Sidebar -->
    <!-- All the following values will be replaced by varibles -->
    <td id="sidebar">
      <div class="sect first-sect">
      <h2>Login to Microblog</h2>
        <% form_tag({:controller => :login, :action => :index},
            :method => :post) do -%>
          <p>
            <label for="name" class="label_input">Name: </label>
            <%= text_field_tag :name, params[:name], :size => 32 -%>
          </p>
          <p>
            <label for="user_password" class="label_input">Password: </label>
            <%= password_field_tag :password, params[:password], :size => 32-%>
          </p>
          <p class="act">
            <%= submit_tag "Login", :class => "formbutton" -%>
          </p>
        <% end -%>
      </div>
      <div class="sect">
        <h2>Widgets</h2>
        <ul>
          <li>Some widgets</li>
        </ul>
      </div>
      <div class="sect">
        <h2>More...</h2>
        <ul>
          <li>Something More.</li>
        </ul>
      </div>
    </td>
  </tr>
</table>

<% else -%>
<% if @notices.size  -%>
  <% @notices.each do |n| -%>
    <div class="sysmsg"><%= n -%></div>
  <% end -%>
<% end -%>
<table id="columns">
  <tr>
    <!-- Main Messages -->
    <td id="main">
      <div id="update">
        <% form_tag({:controller => :message, :action => "post"},
          :method => :post, :class => "limit", :id => "message") do -%>
        <h2>What are you doing?</h2> 
        <p> 
          <textarea name="content" rows="3" cols="70" class="qs"></textarea> 
        </p> 
        <p class="act"> 
          <input type="submit" class="formbutton" title="Post" value="Post" /> 
        </p> 
        <p class="tip">You can input up to 140 charactors.</p>  
        <% end -%>
      </div>
      
      <div id="content">
        <div id="stream" class="message">
          <ol class="wa solo">
            <% session[:ori_uri] = request.request_uri -%>
            <% @messages.each do |message| -%>
            <!-- Dirty way to solve problem. consider using a new local var -->
              <% user = User.find(message.user_id) -%>
              <li class="unlight">
                <%= link_to(image_tag(user.avatar, :alt => user.display_name).to_s, {:controller => :message, :action => :user, :id => user.id}, :class => "avatar", :title => user.display_name.to_s) -%>
                <%= link_to(user.display_name, {:controller => :message, :action => :user, :id => user.id}, :title => user.display_name.to_s) -%>
                <span class="content"><%= message.content -%></span>
                <span class="stamp"><%= link_to("Posted about " + time_string(Time.now.to_i - message.post_at.to_i) + " ago", {:controller => :message, :action => "show", :id => message.id}, :class => "time") -%></span>
                <span class="op">
                  <% if session[:user_name] != nil and session[:user_name] != user.name-%>
                    <%= link_to("Add to favorite", {:controller => :favorite, :action => "add", :id => message.id}, :class => "post_act share") -%>
                  <% end -%>
                  <% if session[:user_name] == user.name  -%>
                      <%= link_to("Delete", {:controller => :message, :action => "delete", :id => message.id}, :class => "delete", :confirm => "Do you really want to delete this message?") -%>
                  <% end -%>
                </span>
              </li>
            <% end -%>
          </ol>
        </div>
        <% if @paged -%>
          <ul class="paginator">
            <% if @page > 1 -%>
              <li><%= link_to("&lt;&lt; Previous", :controller => :home, :action => "index", :page => (@page - 1)) -%></li>
            <% end -%>
            <% if @page < @page_count -%>
              <li><%= link_to("Next &gt;&gt;", :controller => :home, :action => "index", :page => (@page + 1)) -%></li>
            <% end -%>
          </ul>
        <% end -%>
      </div>
    </td>
    
    <!-- Sidebar -->
    <!-- All the following values will be replaced by varibles -->
    <td id="sidebar">
      <div id="user_top">
        <a href="/message"><%= image_tag(@user.avatar) -%>
        <h2><%= @user.display_name -%></h2></a>
      </div>
      <ul id="user_stats">
        <li>
          <a href="/friend">
            <span class="count"><%= Follower.friend_count(@user.id) -%></span>
            <span class="label">Friends</span>
          </a>
        </li>
        <li>
          <a href="/friend?opt=f">
            <span class="count"><%= Follower.follower_count(@user.id) -%></span>
            <span class="label">Followers</span>
          </a>
        </li>
        <li>
          <a href="/message">
            <span class="count"><%= Message.message_count(@user.id) -%></span>
            <span class="label">Messages</span>
          </a>
        </li>
      </ul>
      <div class="stabs">
        <ul>
          <li class="Current">
            <a href="/home">
              <span class="label">Home</span>
            </a>
          </li>
          <li>
            <a href="/message/at">
              <span class="label">@Replies</span>
            </a>
          </li>
          <li>
            <a href="/direct_message">
              <span class="label">Direct Messages (<%= @dm_count -%>)</span>
            </a>
          </li>
          <li>
            <a href="/favorite">
              <span class="label">Favorites</span>
            </a>
          </li>
        </ul>
      </div>
    </td>
  </tr>
</table>
<% end -%>